from typing import Optional
from uuid import UUID
from datetime import datetime
from pydantic import BaseModel, Field


class DocumentTagBase(BaseModel):
    """文档标签基础模型"""
    name: str = Field(..., description="标签名称", max_length=50)
    color: str = Field(default="#007bff", description="标签颜色")


class DocumentTagCreate(DocumentTagBase):
    """创建文档标签请求模型"""
    pass


class DocumentTagUpdate(BaseModel):
    """更新文档标签请求模型"""
    name: Optional[str] = Field(None, description="标签名称", max_length=50)
    color: Optional[str] = Field(None, description="标签颜色")


class DocumentTagResponse(DocumentTagBase):
    """文档标签响应模型"""
    id: UUID
    created_at: datetime
    document_count: int = Field(default=0, description="关联的文档数量")

    class Config:
        from_attributes = True


class DocumentTagWithCount(DocumentTagResponse):
    """带文档数量的标签响应模型"""
    document_count: int = Field(description="关联的文档数量")


class TagSearchRequest(BaseModel):
    """标签搜索请求模型"""
    search_term: str = Field(..., description="搜索关键词", min_length=1)
    limit: int = Field(default=10, description="返回数量限制", ge=1, le=50)
